/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 translation_animation.cpp

	$Header: /heroes4/translation_animation.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )
#include "translation_animation.h"

#include "battlefield.h"
#include "combat_creature.h"
#include "game_time.h"

// ------------------------------------------------------------------------
// play an animation which shows the creature sliding to a new position
// ------------------------------------------------------------------------
t_translation_animation::t_translation_animation( t_combat_creature& creature, 
												  t_map_point_3d const& destination )
					   : t_counted_animation( creature.get_battlefield() ),  m_creature( creature ),
						 t_counted_idle_processor(100)
{
	m_origin = creature.get_position();
	creature.clear_influence();
	if (creature.is_in_tower())
		creature.remove_from_tower();
	m_destination = destination;
	m_delta = m_destination - m_origin;
	m_sum = t_map_point_3d(0,0,0);
	m_frames = 15;
}

// ------------------------------------------------------------------------
// play an animation which shows the creature sliding to a new position
// ------------------------------------------------------------------------
void t_translation_animation::on_idle()
{
	t_map_point_3d position;

	m_sum += m_delta;
	position = (m_sum / 15) + m_origin;
	m_battlefield.move_object( m_creature, position );
	if (--m_frames > 0)
		return;
	assert( position == m_destination );

	if (m_battlefield.get_tower( m_creature.get_cell_position(),
								 m_creature.get_footprint() ) != 0)
		m_creature.place_in_tower();

	t_idle_ptr ref = this;

	animation_ended();
	suspend_idle_processing();
	m_creature.set_influence();
	m_creature.set_wait_animation();
	m_battlefield.end_animation( m_creature );
}

